package nowcoder;

import java.io.*;
import java.lang.management.ManagementFactory;
import java.util.*;

public class D_68_bfs {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static int[] d = new int[610];
    static int[] dx = {1, -1, 10, -10, 100, -100, 300, -300};

    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void bfs() {
        Arrays.fill(d, -1);
        Queue<Integer> q = new LinkedList<>();
        q.offer(10);
        d[10] = 0;

        while (!q.isEmpty()) {
            int t = q.poll();
            for (int i = 0; i < 8; i ++ ) {
                int x = t + dx[i];
                x = Math.min(300, x);
                x = Math.max(10, x);
                if (d[x] != -1) continue;
                q.offer(x);
                d[x] = d[t] + 1;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        bfs();
        int t = cin();
        while (t -- > 0) {
            int a, b, c, dd;
            a = cin(); b = cin(); c = cin(); dd = cin();
            out.println(d[a] + d[b] + d[c] + d[dd]);
        }
        out.flush();
    }
}
